﻿using System;
using System.Globalization;
using System.Text;

namespace T4UtilityBelt.UxDesigns.Styles
{
    public struct Thickness
    {
        private double _bottom;
        private double _left;

        private double _right;
        private double _top;

        public Thickness(double uniformLength)
        {
            double num = uniformLength;
            double num1 = num;
            _bottom = num;
            double num2 = num1;
            double num3 = num2;
            _right = num2;
            double num4 = num3;
            double num5 = num4;
            _top = num4;
            _left = num5;
        }

        public Thickness(double left, double top, double right, double bottom)
        {
            _left = left;
            _top = top;
            _right = right;
            _bottom = bottom;
        }

        public double Bottom
        {
            get { return _bottom; }
            set { _bottom = value; }
        }

        public double Left
        {
            get { return _left; }
            set { _left = value; }
        }

        public double Right
        {
            get { return _right; }
            set { _right = value; }
        }

        public double Top
        {
            get { return _top; }
            set { _top = value; }
        }

        public override bool Equals(object obj)
        {
            if (!(obj is Thickness))
            {
                return false;
            }
            else
            {
                var thickness = (Thickness) obj;
                return this == thickness;
            }
        }

        public bool Equals(Thickness thickness)
        {
            return this == thickness;
        }

        public override int GetHashCode()
        {
            return _left.GetHashCode() ^ _top.GetHashCode() ^ _right.GetHashCode() ^ _bottom.GetHashCode();
        }

        internal static string InternalToString(double l, CultureInfo cultureInfo)
        {
            if (!double.IsNaN(l))
            {
                return Convert.ToString(l, cultureInfo);
            }
            else
            {
                return "Auto";
            }
        }

        public static bool operator ==(Thickness left, Thickness right)
        {
            if (left._left != right._left || left._top != right._top || left._right != right._right)
            {
                return false;
            }
            else
            {
                return left._bottom == right._bottom;
            }
        }

        public static bool operator !=(Thickness left, Thickness right)
        {
            return !(left == right);
        }

        public override string ToString()
        {
            return ToString(CultureInfo.InvariantCulture);
        }

        internal string ToString(CultureInfo cultureInfo)
        {
            const char numericListSeparator = '.'; // TokenizerHelper.GetNumericListSeparator(cultureInfo);
            var stringBuilder = new StringBuilder(64);
            stringBuilder.Append(InternalToString(_left, cultureInfo));
            stringBuilder.Append(numericListSeparator);
            stringBuilder.Append(InternalToString(_top, cultureInfo));
            stringBuilder.Append(numericListSeparator);
            stringBuilder.Append(InternalToString(_right, cultureInfo));
            stringBuilder.Append(numericListSeparator);
            stringBuilder.Append(InternalToString(_bottom, cultureInfo));
            return stringBuilder.ToString();
        }
    }
}